<%@ page import="org.springframework.web.context.request.SessionScope" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.9.14/css/layui.css">
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/jquery-2.1.0.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/layui_ext/xmSelect/xm-select.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/crypto-js.js"></script>
    <script src="${pageContext.request.contextPath}/layui-v2.9.14/echarts.js"></script>
    <title>工单展示</title>
</head>
<body>


<form class="layui-form layui-row layui-col-space16">
    <div class="layui-col-md4">
        <div class="layui-input-wrap">
            <div class="layui-input-prefix">
                <i class="layui-icon layui-icon-username"></i>
            </div>
           <div id="demo1" style="width:300px; margin: 20px;"></div>
        </div>
    </div>

    <div class="layui-btn-container layui-col-xs12">
        <button class="layui-btn" lay-submit lay-filter="demo-table-search">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
    </div>
</form>
<div id="main" style="width: 600px;height:400px;"></div>
<button class="layui-btn" lay-on="e1">报修</button>
<button class="layui-btn" lay-on="e2">导出excel</button>
<button class="layui-btn" lay-on="e3">选中导出excel</button>
<table class="layui-hide" id="ID-table-demo-search"></table>
<div style="display: none" id="fp">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <input type="hidden" name="id" id="id">
            <label class="layui-form-label">验证必填项</label>
            <div class="layui-input-block">
                <div id="demo2" style="width:300px; margin: 20px;"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">分配</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<%--<div style="display: none" id="order">--%>
<%--    <h3>工单内容</h3>--%>
<%--工单单号：<span id="orderId"></span><br>--%>
<%--工单分类：<span id="typeId"></span><br>--%>
<%--报修小区：<span id="communityId"></span><br>--%>
<%--报修人：  <span id="submitterId"></span><br>--%>
<%--报修电话：<span id="submitterPhone"></span><br>--%>
<%--报修时间：<span id="submitterTime"></span><br>--%>
<%--工单内容：<span id="title"></span><br>--%>
<%--&lt;%&ndash;显示图片&ndash;%&gt;--%>
<%--    <div id="myImages"></div>--%>
<%--    <hr>--%>
<%--    <h3>报修处理</h3>--%>
<%--    <div id="detail">--%>

<%--    </div>--%>
<%--</div>--%>
<script type="text/html" id="toolDemo">
    <div class="layui-clear-space">
        <a class="layui-btn layui-btn-xs" lay-event="fp"  style="display: {{d.statusType==0?'':'none'}}">分配</a>
        <a class="layui-btn layui-btn-xs" lay-event="ja"  style="display: {{d.statusType==2?'':'none'}}">结案</a>
        <a class="layui-btn layui-btn-xs" lay-event="pj"  style="display: {{d.statusType==3?'':'none'}}">评价</a>
        <a class="layui-btn layui-btn-xs" lay-event="toDetail">查看</a>
    </div>
</script>
<script>
    layui.use(function(){
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table;
        var $ = layui.$;
        var util = layui.util;
        util.on({
            e1: function(){
                location.href="/order/toAdd.do";
            },
            e2:function (){
                location.href="/order/exportExcel.do"
            },
            e3:function (){
                var checkStatus = table.checkStatus('ID-table-demo-search')
                var data = checkStatus.data; // 获取选中的数据
                let ids = data.map(function (item){
                    return item.id
                }).join('');
                if(ids==''){
                    layer.msg("请选择要导出的数据",{time:2000})
                }else{
                    location.href="/order/exportExcel2.do?ids="+ids
                }
            }
        });
        // 工具栏事件
        // 触发单元格工具事件
        table.on('tool(ID-table-demo-search)', function(obj) { // 双击 toolDouble
            var data = obj.data; // 获得当前行数据
            // console.log(obj)
            if (obj.event === "fp") {
                //为表单的隐藏域id--工单的id
                $("#id").val(data.id)
                layer.open({
                    title: '分配 - id:' + data.id,
                    type: 1,
                    area: ['40%', '40%'],
                    content:$("#fp")
                });
            }else if(obj.event==='toDetail'){
                // layer.open({
                //     title: '工单详情',
                //     type: 1,
                //     area: ['60%', '80%'],
                //     content:$("#order"),
                //     success:function () {
                //         $("#orderId").text(data.id)
                //         $("#typeId").text(data.orderTypeName)
                //         $("#communityId").text(data.communityName+data.content)
                //         $("#submitterId").text(data.submitterId)
                //         $("#submitterPhone").text(data.submitterPhone)
                //         $("#submitterTime").text(data.communityName+data.submitterTime)
                //         $("#title").text(data.title)
                //         let images = data.images.split(",")
                //         for (let i = 0; i < images.length; i++) {
                //             $("#myImages").append("<img src='"+images[i]+"' style='width: 100px; height: 100px;'>")
                //         }
                //     //    施工明细
                //         $.post("/order/detail.do",{'orderId':data.id},function (res){
                //             let data = res.data;
                //             $("detail").empty()
                //             for (let i = 0; i < data.length; i++) {
                //                 $("#detail").append("<hr>")
                //                 $("#detail").append(data[i].worker+" "+data[i].createTime+"<br>")
                //                 $("#detail").append("处理内容："+data[i].content+"<br>")
                //                 if(data[i].images!=null&&data[i].images!=""){
                //                     let images2 = data[i].images.split(",")
                //                     for (let j = 0; j < images2.length; j++) {
                //                         $("#detail").append("<img src='"+images2[j]+"' style='width: 100px;height: 100px'>")
                //                     }
                //                 }
                //             }
                //         })
                //     }
                // });
                location.href="/order/toDetail.do?orderId="+data.id
            }
        })
        //提交工人--分配工人
        form.on('submit(demo1)',function (data){
            var field = data.field;//获取表单字段
            $.post('/order/fp.do',field,function (res) {
                if(res.code==0){
                layer.msg(res.msg,{time:1000},function (){
                    layer.closeAll();
                //    刷新列表
                    table.reload('ID-table-demo-search')
                })
                }else{
                    layer.msg(res.msg,{time:1000});
                }
            })
            return false;
        })
        // 获取所有社区，并且转成json格式
        let communityData = JSON.parse('${community}')
        // 渲染多选小区
        var demo1 = xmSelect.render({
            el: '#demo1',
            data: communityData
        })

        let workerListData = JSON.parse('${userList}')
        // 渲染多选分配的人员
        var demo2 = xmSelect.render({
            el: '#demo2',
            data: workerListData
        })
        // 创建表格实例
        table.render({
            elem: '#ID-table-demo-search',
            url: '/order/list.do', // 此处为静态模拟数据，实际使用时需换成真实接口
            parseData:function (res){
                return{
                    code:res.code,
                    data:res.data.list,
                    count:res.data.total

                }
            },limit:3,
            cols: [[
                {type: 'checkbox', title: '😊', fixed: true}, // 单选框
                {field:'id', title: '序号', width:80, sort: true, fixed: true},
                {field:'communityName', title: '所属小区'},
                {field:'orderTypeName', title: '工单类型'},
                {field:'title', title: '报修小区',},
                {field:'submitter', title: '报修人',},
                {field:'submitterTime', title: '报修时间'},
                {field:'username', title: '处理人'},
                {field:'createTime', title: '处理时间'},
                {field:'statusTypeName', title: '状态'},
                {fixed: 'right', title:'操作', width: 134, minWidth: 185, templet: '#toolDemo'}
            ]],
            page: true,
            height: 310
        });
        // 日期
        laydate.render({
            elem: '.demo-table-search-date'
        });
        // 搜索提交
        form.on('submit(demo-table-search)', function(data){
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('ID-table-demo-search', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            layer.msg('搜索成功');
            return false; // 阻止默认 form 跳转
        });
    });
</script>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));


    // 指定图表的配置项和数据
    var option = {
        title: {
            text: 'ECharts 入门示例'
        },
        tooltip: {},
        legend: {
            data: ['销量']
        },
        xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
            {
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }
        ]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
</script>
</body>
</html>